#include "picothreads.hpp"

#include "log.hpp"

namespace vl
{

int global = 0;

struct A : picothread
{
	void go()
	{
		PT_WaitUntil(global == 1);
		ILOG("Global is " << global);
	}
};

struct B : picothread
{
	void go()
	{
		ILOG("Global will be set to 1");
		global = 1;
	}
};

struct Fib : generator<int>
{
	void go()
	{
		int a = 1;
		int b = 1;
		
		for(; ;)
		{
			int t = a;
			a = b;
			b += t;
			
			PT_Yield(a);
		}
	}
};

void test_picothreads()
{	
	generator_iterator<int> i(new Fib), e;
	
	int c = 0;
	
	for(; i != e && c < 10; ++i, ++c)
	{
		ILOG("Value " << *i);
	}
}

}